/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SocialValuesSliderPanelTest.java
 *
 * Created on Aug 13, 2009, 3:37:12 PM
 */
package SocialValueSliderPackage;


import ccpv.FileManager;
import ccpv.RunTimeSettings;
import java.awt.Dimension;
import java.io.File;
import java.lang.String;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTree;

/**
 *
 * @author Heather
 */
public class SocialValuesSliderPanelTest extends javax.swing.JApplet
{

  public static void main(String[] args)
  {
    SocialValuesSliderPanelTest test = new SocialValuesSliderPanelTest();
    test.setSize(defaultAppSize);
    JFrame windowFrame = new JFrame();
    windowFrame.add(test.getContentPane());
    windowFrame.setSize(defaultAppSize);
    windowFrame.setPreferredSize(defaultAppSize);
    windowFrame.pack();
  }

  public SocialValuesSliderPanelTest()
  {
    init();
  }

  /** Initializes the applet SocialValuesSliderPanelTest */
  public void init()
  {
    try
    {
      java.awt.EventQueue.invokeAndWait(new Runnable()
      {

        public void run()
        {
          initComponents();

          testContainer.setSize(svspSize);
          testContainer.setPreferredSize(svspSize);

          JTree tTree = new JTree();
          svsp = new SocialValuesSliderPanel(tTree);
          svsp.setSize(svspSize);
          svsp.setPreferredSize(svspSize);
          svsp.setVisible(false);
          
          svspFrame.setLayout(null);
          svspFrame.add(svsp);
          svspFrame.setSize(svsp.getSize());
          svspFrame.setPreferredSize(svsp.getSize());
          svspFrame.setVisible(true);
          svspFrame.pack();
          svspFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          instructionsTextPane.setText(instructions);

          // setup and display opening dialog
          openingDialog.setSize(openingDialogSize);
          openingDialog.setPreferredSize(openingDialogSize);
          openingDialog.setVisible(true);

        }
      });
    } catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }

  /** This method is called from within the init() method to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    openingDialog = new javax.swing.JDialog();
    jPanel1 = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    instructionsTextPane = new javax.swing.JTextArea();
    jLabel1 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    selectDataFileButton = new javax.swing.JButton();
    fileChooser = new javax.swing.JFileChooser();
    fileErrorDialog = new javax.swing.JDialog();
    jPanel2 = new javax.swing.JPanel();
    jLabel2 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    testContainer = new javax.swing.JPanel();

    openingDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    jPanel1.setBackground(new java.awt.Color(255, 255, 204));
    jPanel1.setLayout(null);

    instructionsTextPane.setColumns(20);
    instructionsTextPane.setEditable(false);
    instructionsTextPane.setFont(new java.awt.Font("Times New Roman", 1, 16));
    instructionsTextPane.setForeground(new java.awt.Color(0, 0, 153));
    instructionsTextPane.setRows(5);
    jScrollPane1.setViewportView(instructionsTextPane);

    jPanel1.add(jScrollPane1);
    jScrollPane1.setBounds(10, 80, 590, 310);

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
    jLabel1.setText("Welcome.  Please follow these instructions.");
    jPanel1.add(jLabel1);
    jLabel1.setBounds(10, 10, 590, 30);

    jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
    jLabel3.setText("Step 2: Select the data file containing the group information.");
    jPanel1.add(jLabel3);
    jLabel3.setBounds(10, 400, 590, 30);

    jLabel4.setFont(new java.awt.Font("Tahoma", 1, 18));
    jLabel4.setText("Step 1: Read the following directions.");
    jPanel1.add(jLabel4);
    jLabel4.setBounds(10, 50, 430, 30);

    selectDataFileButton.setFont(new java.awt.Font("Tahoma", 1, 14));
    selectDataFileButton.setText("Select Data File");
    selectDataFileButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        selectDataFileButtonActionPerformed(evt);
      }
    });
    jPanel1.add(selectDataFileButton);
    selectDataFileButton.setBounds(10, 430, 590, 50);

    javax.swing.GroupLayout openingDialogLayout = new javax.swing.GroupLayout(openingDialog.getContentPane());
    openingDialog.getContentPane().setLayout(openingDialogLayout);
    openingDialogLayout.setHorizontalGroup(
      openingDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 799, Short.MAX_VALUE)
    );
    openingDialogLayout.setVerticalGroup(
      openingDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 550, Short.MAX_VALUE)
    );

    jPanel2.setBackground(new java.awt.Color(255, 204, 204));

    jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
    jLabel2.setText("Error in loading file.  Please try a different file.");

    jLabel5.setText("FileManager class.");

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel2Layout.createSequentialGroup()
            .addGap(24, 24, 24)
            .addComponent(jLabel2))
          .addGroup(jPanel2Layout.createSequentialGroup()
            .addGap(98, 98, 98)
            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addContainerGap(32, Short.MAX_VALUE))
    );
    jPanel2Layout.setVerticalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(18, 18, 18)
        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(30, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout fileErrorDialogLayout = new javax.swing.GroupLayout(fileErrorDialog.getContentPane());
    fileErrorDialog.getContentPane().setLayout(fileErrorDialogLayout);
    fileErrorDialogLayout.setHorizontalGroup(
      fileErrorDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );
    fileErrorDialogLayout.setVerticalGroup(
      fileErrorDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );

    testContainer.setLayout(null);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(testContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 1305, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(testContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 759, Short.MAX_VALUE)
    );
  }// </editor-fold>//GEN-END:initComponents

  private void selectDataFileButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_selectDataFileButtonActionPerformed
  {//GEN-HEADEREND:event_selectDataFileButtonActionPerformed
    // TODO add your handling code here:
    int openVal = fileChooser.showOpenDialog(openingDialog);
    if (openVal == JFileChooser.APPROVE_OPTION)
    {
      File socialDataFile = fileChooser.getSelectedFile();
      // COMMENT OUT IF WANT TO TEST ON REAL DATA
      String fileName = socialDataFile.getAbsolutePath();
      System.out.println(fileName);
      try
      {
        RunTimeSettings rt = FileManager.csvReader(fileName);
        System.out.println("hey");
        svsp.setAllAscriptiveTrees(rt.ascriptive_names);
        openingDialog.setVisible(false);
        svsp.setVisible(true);
        svsp.setRunTimeSettings(rt);
      } catch (Error c)
      {
        System.out.println("ERROR: Loading of data file failed.  Please load another file.");
        Dimension errorDialogD = new Dimension(340, 140);
        fileErrorDialog.setSize(errorDialogD);
        fileErrorDialog.setPreferredSize(errorDialogD);
        fileErrorDialog.setVisible(true);
      }
    }

    // COMMENT THIS OUT BEFORE SHIPPING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    //openingDialog.setVisible(false);
    //svsp.setVisible(true);
}//GEN-LAST:event_selectDataFileButtonActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JFileChooser fileChooser;
  private javax.swing.JDialog fileErrorDialog;
  private javax.swing.JTextArea instructionsTextPane;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JDialog openingDialog;
  private javax.swing.JButton selectDataFileButton;
  private javax.swing.JPanel testContainer;
  // End of variables declaration//GEN-END:variables
  SocialValuesSliderPanel svsp;
  JFrame svspFrame = new JFrame();
  GroupDetailsPanel gDP = new GroupDetailsPanel();
  boolean fileChosen = false;
  Dimension svspSize = new Dimension(820, 690);
  Dimension openingDialogSize = new Dimension(630, 525);
  static Dimension defaultAppSize = new Dimension(630, 630);
  // for instructions
  private String instructions =
          "Using the sliders, please enter your perception of the level of positive or negative\n" +
          "altruism, on average, by members of the first group listed towards the second group.\n" +
          "Altruism is defined as a sense of identification and closeness that would cause a\n" +
          "member of the first group to sacrifice her/his own interests to help (positive) or\n" +
          "hurt (negative) members of the second group.  When the first and second group are the\n" +
          "same, this would indicate the average altruism felt by a member of a group to other\n" +
          "members of the same group, i.e.  a person's identification with her/his own group.\n" +
          "1 indicates very strong positive altruism, 0 indifference, and -1 very strong negative\n" +
          "altruism.    One way to think about it concretely is as follows:  Suppose a member of\n" +
          "the first group on average would be willing to pay up to $30 if this would cause\n" +
          "members of the second group to gain a total of $100.  This  would correspond to an\n" +
          "altruism of 0.3.   Suppose the member of the first group on average would be willing\n" +
          "to pay up to $15 in order to take a total of $100 away from members of the second\n" +
          "group.  This would correspond to altruism of -0.15.   Suppose a member of the first\n" +
          "group would not be willing to pay anything to change the condition of members of the\n" +
          "second group, for better or worse.  This would correspond to altruism of 0.";
}
